package edu.thu.studio.ormdesigner.editor.figure.border;

import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.LineBorder;
import org.eclipse.draw2d.geometry.Insets;
import org.eclipse.swt.graphics.Color;

public class LineWidthBorder extends LineBorder {
    private int top;
    private int right;
    private int bottom;
    private int left;
    
    public LineWidthBorder(Color nodeBorderColor, int i, int top, int right, int bottom, int left) {
        super(nodeBorderColor, i);
        this.top = top;
        this.left = left;
        this.bottom = bottom;
        this.right = right;
    }
    
    public Insets getInsets(IFigure figure) {
        return new Insets(top * this.getWidth(), right * this.getWidth(), bottom * this.getWidth(), left
            * this.getWidth());
    }
    
    public void paint(IFigure figure, Graphics graphics, Insets insets) {
        graphics.setForegroundColor(this.getColor());
        graphics.setLineWidth(this.getWidth());
        if (top > 0) {
            graphics.drawLine(getPaintRectangle(figure, insets).getTopLeft(), tempRect.getTopRight());
        }
        if (right > 0) {
            graphics.drawLine(getPaintRectangle(figure, insets).getTopRight(), tempRect.getBottomRight());
        }
        if (bottom > 0) {
            graphics.drawLine(getPaintRectangle(figure, insets).getBottomLeft(), tempRect.getBottomRight());
        }
        if (left > 0) {
            graphics.drawLine(getPaintRectangle(figure, insets).getTopLeft(), tempRect.getBottomLeft());
        }
    }
}